package 线程池.forkjoin;

import java.util.concurrent.RecursiveTask;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/8/15 11:04
 * @description:
 * @version:
 */
class FibonacciTask extends RecursiveTask<Integer> {
    private final int n;

    FibonacciTask(int n) {
        this.n = n;
    }

    @Override
    protected Integer compute() {
        if (n <= 1) {
            return n;
        } else {
            FibonacciTask task1 = new FibonacciTask(n - 1);
            FibonacciTask task2 = new FibonacciTask(n - 2);
            task1.fork();
            return task2.compute() + task1.join();
        }
    }
}